
#include "ServerManager.h"
#include "DumpManager.h"

#include "comm_def.h"

#include <iostream>

std::shared_ptr<spdlog::logger> gLogger;

std::shared_ptr<spdlog::sinks::stdout_color_sink_mt> gStdSink;
std::shared_ptr<spdlog::sinks::daily_file_sink_mt> gDailyFileSink;

void CustomMain()
{
	ServerManager sm;
	if (!sm.InitServerManager())
	{ //初始化服务失败

		return;
	}
	sm.StartServerManager();
}

bool InitLogMoudle()
{
	bool bret = false;
	try
	{
		gStdSink = std::make_shared<spdlog::sinks::stdout_color_sink_mt>();
		gStdSink->set_level(spdlog::level::warn);

		gDailyFileSink = std::make_shared<spdlog::sinks::daily_file_sink_mt>(LOG_FILE_NAME, true, 0, 0);
		gDailyFileSink->set_level(spdlog::level::info);
		gLogger = std::shared_ptr<spdlog::logger>(new spdlog::logger(LOGGER_NAME, { gStdSink, gDailyFileSink }));
		spdlog::register_logger(gLogger);
		auto ccc = spdlog::get(LOGGER_NAME);
		gLogger->info("initial logger success");

		bret = true;
	}
	catch (const spdlog::spdlog_ex& ex)
	{
		std::cout << "initial log module failed with  error: " << ex.what() << std::endl;
	}
	catch (...)
	{
		std::cout << "initial log module failed " << std::endl;
	}
	return bret;
}

int main(void)
{
	//注册coredump相关逻辑
	DumpManager dump;
	
	//日志初始化代码在最开始进行
	if (InitLogMoudle())
	{
		CustomMain();
	}
	return 0;
}